//
// Problem 1: gas stations (plus route plan)
//
// Created by tianq on 24-12-5.
//

#include <iostream>
#include <vector>
#include <limits>
#include <unordered_map>
#include <ranges>
using namespace std;
using ull = unsigned long long;

int main() {
    int n, k;  // n: fuel tank size, k: gas stations count
    vector<int> distances; // distance[0] means road from station 0 (start) to station 1

    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        int tmp = 0;
        cin >> tmp;
        distances.emplace_back(tmp);
    }
    // plus version, basically changing from a single counting number to a vector of station ids
    // count min Refill rather than updating whole vector, this should save some time
    ull minRefill = 0; // 0: in case there is no stations between
    unordered_map<int, vector<int> > map; // <GasRemain, vector<StationId>>
    map.emplace(n, 0); // {GasRemain: n, RefillList: {}} note that 0 here means 0 for initial capacity

    for (int i = 0; i < distances.size(); i++) {
        const int ahead = distances[i];
        minRefill = numeric_limits<ull>::max();
        unordered_map<int, vector<int> > newMap;
        for (const auto &[remain, refills]: map) {
            if (remain < ahead) continue;
            if (refills.size() < minRefill) minRefill = refills.size();
            if (int newRemain = remain - ahead;
                !newMap.contains(newRemain) || refills.size() < newMap[newRemain].size()) {
                newMap[newRemain] = refills;
            }
            if (!newMap.contains(n) || refills.size() + 1 < newMap[n].size()) {
                newMap[n] = refills; // since we are using const reference, we can't append Station ID here
                newMap[n].emplace_back(i + 1); // skipping 0, since we are leaving 0 for 1, the refill happens at 1
            }
        }
        map.swap(newMap);
    }

    for (const auto &refills : map | std::views::values) {
        if (refills.size() > minRefill) continue;
        for (const int &id: refills)
            cout << id << " ";
        cout << endl;
        break;
    }
    return 0;
}

